<template>
	<a-card>
		<a-form layout="inline" :model="formState">
			<a-form-item label="用户名称">
				<a-select
					placeholder="请选择用户"
					v-model:value="formState.admin_id"
					:options="peroptions"
					:fieldNames="fieldNames"
				></a-select>
			</a-form-item>
			<a-form-item label="材料名称">
				<a-select
					placeholder="请选择材料名称"
					v-model:value="formState.material_id"
					:options="tableData"
					:fieldNames="fieldNames2"
				></a-select>
			</a-form-item>
			<a-form-item>
				<a-button  style="margin-right: 8px" class="searchButton" type="primary" html-type="submit" @click="loginit">
					查询
				</a-button>
				<a-button  style="margin-right: 8px" class="searchButton" type="primary" html-type="submit" @click="loginitclear">
					清空
				</a-button>
			</a-form-item>
		</a-form>
		<a-table style="margin-top: 10px" ref="table" :pagination="false" :scroll="{ x: 700 }"  :columns="logcolumns" :data-source="logtableData" bordered>
			<template #bodyCell="{ column, text,record }">
				<template v-if="column.dataIndex === 'addtime'">
					{{timeGET(text)}}
				</template>
				<template v-if="column.dataIndex === 'admin_id'">
					{{adminGet(text)}}
				</template>
			</template>
		</a-table>
	</a-card>

</template>

<script>
	import materialJsApi from "@/api/auth/material";
	import indexJsApi from "@/api/auth/index";
	import operationlogJsApi from "@/api/auth/operation_log";
	import adminJsApi from "@/api/auth/admin";
	export default {
		name: "index",
		data(){
			return {
				logShow:false,
				formState:{},
				fieldNames:{ label: 'name', value: 'admin_id' },
				fieldNames2:{ label: 'name', value: 'material_id' },
				peroptions:[],
				addFormData:{},
				LibrariesShow:false,
				titlekey:null,
				fileList:[],
				upLoadShow:false,
				columns:[
					{
						title: '物品名称',
						dataIndex: 'name',
						key: 'name',
						width:'100px'
					},
					{
						title: '物品单位',
						dataIndex: 'unit',
						key: 'unit',
						width:'200px'
					},
					{
						title: '重量(数量)',
						dataIndex: 'weight',
						key: 'weight',
						width:'100px'
					},
					{
						title: '金额',
						dataIndex: 'amount',
						key: 'amount',
						width:'100px'
					},
					{
						title: '操作',
						dataIndex: 'actions',
						key: 'actions',
						align:'center',
						width:'230px'
					},

				],
				tableData:[],
				arritem:{},
				logtableData:[],
				logcolumns:[
					{
						title: '物品名称',
						dataIndex: 'material',
						key: 'material',
						width:'100px'
					},
					{
						title: '用户名称',
						dataIndex: 'admin_id',
						key: 'admin_id',
						width:'100px'
					},
					{
						title: '变动量',
						dataIndex: 'val',
						key: 'val',
						width:'100px'
					},
					{
						title: '备注',
						dataIndex: 'remarks',
						key: 'remarks',
						width:'100px'
					},
					{
						title: '添加时间',
						dataIndex: 'addtime',
						key: 'addtime',
						width:'100px'
					},
				]
			}
		},
		created() {
			this.init()
			this.loginit()
		},
		methods:{
			loginitclear(){
				this.formState = {}
				this.loginit()
			},
			loginit(){
				operationlogJsApi.operationlogList(this.formState).then(res =>{
					this.logtableData = res
				})
			},
			init(){

				materialJsApi.materialList().then(res =>{
					let arr = res.slice(0,-1)
					this.tableData = arr
				})
				adminJsApi.adminList({page:1,...this.formState}).then(res => {
					this.peroptions = res
				})

			},
			handleOk(){
				const formData = new FormData()
			},
			timeGET(VAL){
				var oDate = new Date(VAL),
					oYear = oDate.getFullYear(),
					oMonth = oDate.getMonth() + 1,
					oDay = oDate.getDate(),
					oHour = oDate.getHours(),
					oMin = oDate.getMinutes(),
					oSen = oDate.getSeconds(),
					oTime = oYear + '-' +this.addZero(oMonth) + '-' + this.addZero(oDay) + ' ' + this.addZero(oHour) + ':' +
						this.addZero(oMin) + ':' + this.addZero(oSen);
				return  oTime
			},
			fileChange(file1){
				const formData = new FormData()
				formData.append('file',file1)
				indexJsApi.indexImport(formData).then(res =>{
					this.upLoadShow =false
					this.init()
				})
			},
			addZero(num){
				if (parseInt(num) < 10) {
					num = "0" + num
				}
				return num
			},
			adminGet(val){
				return this.peroptions.filter(item => item.admin_id == val).length>0?this.peroptions.filter(item => item.admin_id == val)[0].name:''
			},
		}
	}
</script>

<style scoped>

</style>
